//
//  FMHotFMTableViewCell.m
//  PsychologyFM
//
//  Created by lanou on 16/1/12.
//  Copyright © 2016年 ZhangLuDu. All rights reserved.
//

#import "FMHotFMTableViewCell.h"
#import "FMRecommendCollectionViewCell.h"
#import "FMLessonAndFMModel.h"
#import "FMDiantaiPlayViewController.h"
#import "FMRootViewController.h"

@interface FMHotFMTableViewCell ()


@end

@implementation FMHotFMTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _modelArray = [NSMutableArray array];
        //  添加collectionView
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        //  行列间距,内边距,滚动方向,item大小
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(10, 15, 5, 10);
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        layout.itemSize = CGSizeMake((kScreenWidth - 30) / 3, kScreenWidth / 3 + 40);
        
        _recommentCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,kScreenWidth, kScreenWidth / 3 + 40) collectionViewLayout:layout];
        _recommentCollectionView.backgroundColor = FMWhite;
        _recommentCollectionView.scrollEnabled = NO;
        _recommentCollectionView.bounces = NO;
        _recommentCollectionView.alwaysBounceHorizontal = NO;
        _recommentCollectionView.alwaysBounceVertical = NO;
        //  设置代理和数据源
        _recommentCollectionView.delegate = self;
        _recommentCollectionView.dataSource = self;
        //  注册cell
        [_recommentCollectionView registerClass:[FMRecommendCollectionViewCell class] forCellWithReuseIdentifier:@"FMRecommendCollectionViewCell"];
        [self.contentView addSubview:_recommentCollectionView];
    }
    return self;
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _modelArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FMRecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FMRecommendCollectionViewCell" forIndexPath:indexPath];
    FMLessonAndFMModel *model = _modelArray[indexPath.row];
    cell.model = model;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld",indexPath.row);
    FMLessonAndFMModel *model = _modelArray[indexPath.row];
    FMDiantaiPlayViewController *diantaiVC = [[FMDiantaiPlayViewController alloc]init];
    diantaiVC.value = model.id;
    diantaiVC.rootVC = _homeVC.rootVC;
    [_homeVC.navigationController pushViewController:diantaiVC animated:YES];
   // [diantaiVC.rootVC.navigationController pushViewController:diantaiVC animated:YES];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
    
    
}

@end
